//Created by  for Jaws.Core.Web
//Original work Copyright(C) 2008.  All Rights Reserved.

using System;
using System.Xml.Serialization;
using Jaws.Core.Web.Entities.Categories;
using Jaws.Core.Web.Entities.Comments;
using Jaws.Core.Web.Entities.Tags;

namespace Jaws.Core.Web.Entities.Pages
{
    [Serializable]
    [XmlDataDirectory("pages")]
    public class Page : XmlBusinessBase<Page>, ICommentable, ICategories, ITagable
    {
        private string slug;

        public string Title { get; set; }

        public string Description { get; set; }

        public string Keywords { get; set; }

        /// <summary>
        /// Gets or sets the Slug of the Page.
        /// A Slug is the relative URL used by the pages.
        /// </summary>
        public string Slug
        {
            get
            {
                if (string.IsNullOrEmpty(slug))
                    return Utils.RemoveIllegalCharacters(Title);

                return slug;
            }
            set { slug = value; }
        }

        [XmlIgnore]
        public bool IsVisible { get; set; }

        [XmlIgnore]
        public string RelativeLink
        {
            get
            {
                return string.Format("{0}page/{1}/", Utils.RelativeWebRoot, Utils.RemoveIllegalCharacters(Slug));
            }
        }

        public Guid Parent { get; set; }

        public bool ShowInList { get; set; }

        public bool IsHomePage { get; set; }

        #region Implementation of ICommentable

        public CommentsCollection Comments { get; set; }

        #endregion

        #region Implementation of ICategories

        public CategoryCollection CategoryCollection { get; set; }

        #endregion

        #region Implementation of ITagable

        public TagCollection TagCollection { get; set; }

        public string Content { get; set; }

        public bool IsPublished { get; set; }

        [XmlIgnore]
        public Uri AbsoluteLink
        {
            get
            {
                return Utils.ConvertToAbsolute(RelativeLink);
            }
        }

        #endregion
    }

}